<template>
  <view class="page-container">
    <!-- 空状态展示 -->
    <view v-if="items.length === 0" class="empty-container">
      <image src="/static/image/no.png" mode="aspectFit" class="empty-img" />
      <text class="empty-text">暂无作品</text>
    </view>

    <!-- 瀑布流布局 -->
    <view v-else class="waterfall-container">
      <view 
        v-for="(item, index) in items"
        :key="index"
        class="waterfall-item"
      >
        <image
          :src="item.image"
          mode="widthFix"
          class="waterfall-img"
        />
        <view class="image-type">{{ item.type }}</view>
        <text class="waterfall-keywords">{{ item.title }}</text>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { ApigetImagesByuser } from '/pages/api/image.js'

const items = ref([])

const getImage = async () => {
  try {
    const res = await ApigetImagesByuser()
    items.value = res
  } catch (error) {
    console.error('获取图片失败:', error)
  }
}

onMounted(() => {
  getImage()
})
</script>

<style scoped lang="less">
.page-container {
  min-height: 100vh;
  background-color: #f5f5f5;
}

/* 瀑布流核心样式 */
.waterfall-container {
  column-count: 2;
  column-gap: 15px;
  padding: 15px;
}

.waterfall-item {
  break-inside: avoid;
  margin-bottom: 15px;
  width: 100%;
  background-color: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  position: relative;
}

.waterfall-img {
  width: 100%;
  display: block;
}

.image-type {
  position: absolute;
  top: 10px;
  right: 10px;
  color: white;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.7);
  font-size: 14px;
  font-weight: 500;
  z-index: 1;
}

/* 修改后的描述文本样式 */
.waterfall-keywords {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 5; /* 控制显示5行 */
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0px 10px;
  font-size: 13px;
  color: #666;
  line-height: 1.5;
  word-break: break-all;
}

/* 空状态样式 */
.empty-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 80vh;
}

.empty-img {
  width: 200px;
  height: 200px;
  object-fit: contain;
}

.empty-text {
  margin-top: 20px;
  color: #999;
  font-size: 16px;
}

/* 响应式适配 */
@media (min-width: 768px) {
  .waterfall-container {
    column-count: 3;
  }
}

@media (min-width: 1024px) {
  .waterfall-container {
    column-count: 4;
  }
}
</style>